﻿$(document).ready(function (){
	$("#map-northAlanStreet").hide();
	$("#map-eastAlanStreet").hide();
	$("#map_apartment").hide();
	$("#map_bookshop").hide();
	$("#map_park").hide();
	$("#map_school").hide();
	$("#map_payment").hide();
	$("#map_account").hide();		
	$("#map_activity").hide();
	
	//up
	$("#clickUp").mouseover(function(){
		$("#clickUp").attr("src","./images/up.gif");
	});
	$("#clickUp").mouseout(function(){
		$("#clickUp").attr("src","./images/up1.gif");
	});
	$("#clickUp").click(function(){
		$("#map-mainAlanStreet").hide(2000);
		$("#map-northAlanStreet").fadeIn(2000);
	});
	
	//down
	$("#clickDown").mouseover(function(){
		$("#clickDown").attr("src","./images/down.gif");
	});
	$("#clickDown").mouseout(function(){
		$("#clickDown").attr("src","./images/down1.gif");
	});
	$("#clickDown").click(function(){
		$("#map-northAlanStreet").hide(2000);
		$("#map-mainAlanStreet").show(2000);
	});
	
	//right
	$("#clickRight").mouseover(function(){
		$("#clickRight").attr("src","./images/right.gif");
	});
	$("#clickRight").mouseout(function(){
		$("#clickRight").attr("src","./images/right1.gif");
	});
	$("#clickRight").click(function(){
		$("#map-eastAlanStreet").show(2000);
		$("#map-mainAlanStreet").hide(2000);
	});
	
	//left
	$("#clickLeft").mouseover(function(){
		$("#clickLeft").attr("src","./images/left.gif");
	});
	$("#clickLeft").mouseout(function(){
		$("#clickLeft").attr("src","./images/left1.gif");
	});
	$("#clickLeft").click(function(){
		$("#map-eastAlanStreet").hide(2000);
		$("#map-mainAlanStreet").show(2000);
	});
	
	//apartment
	$("#click_apartment").click(function(){
		$("#map-mainAlanStreet").hide(2000);
		$("#map_apartment").show(2000);		
	});
	
	//apartment left
	$("#apartment_clickLeft").mouseover(function(){
		$("#apartment_clickLeft").attr("src","./images/left.gif");
	});
	$("#apartment_clickLeft").mouseout(function(){
		$("#apartment_clickLeft").attr("src","./images/left1.gif");
	});
	$("#apartment_clickLeft").click(function(){
		$("#map_apartment").hide(2000);
		$("#map-mainAlanStreet").show(2000);
	});
	
	//park right
	$("#park_clickRight").mouseover(function(){
		$("#park_clickRight").attr("src","./images/right.gif");
	});
	$("#park_clickRight").mouseout(function(){
		$("#park_clickRight").attr("src","./images/right1.gif");
	});
	$("#park_clickRight").click(function(){
		$("#map_park").hide(2000);
		$("#map-mainAlanStreet").show(2000);
	});
	
	//bookshop
	$("#click_bank").click(function(){
//		$("#map-eastAlanStreet").hide(2000);
//		$("#map_payment").show(2000);	
//		$("#map-eastAlanStreet").hide(2000);
//		$("#map_bookshop").show(2000);
		window.location.href = "payment.html";
	});
	
	//bookshop
	$("#click_bookshop").click(function(){
//		$("#map-eastAlanStreet").hide(2000);
//		$("#map_bookshop").show(2000);
		window.location.href = "bookshop.html";
	});
	
	//park
	$("#click_park").click(function(){
		$("#map-northAlanStreet").hide(2000);
		$("#map_park").show(2000);
		$("#parkchat").hide();
	});
	
	//account
	$("#account_clickLeft").mouseover(function(){
        $("#account_clickLeft").attr("src","./images/left.gif");
    });
    $("#account_clickLeft").mouseout(function(){
        $("#account_clickLeft").attr("src","./images/left1.gif");
    });
    $("#account_clickLeft").click(function(){
        window.location.href = "alanstreet.html";
    });
    
    //activity
	$("#activity_clickLeft").mouseover(function(){
        $("#activity_clickLeft").attr("src","./images/left.gif");
    });
    $("#activity_clickLeft").mouseout(function(){
        $("#account_clickLeft").attr("src","./images/left1.gif");
    });
    $("#activity_clickLeft").click(function(){
        window.location.href = "alanstreet.html";
    });
	
	//click_bank
	$("#click_bank").click(function(){
		window.location.href = "alanbank.html";
	});
	
	//levelup
	$("#click_school").click(function(){
		$("#map-mainAlanStreet").hide(2000);
		$("#map_school").show(2000);	
		//quiz
		var question = 0;
		var correct = 0;
		//test
		$.ajax({
			type:"GET",
			url:"index/quiz/",
			async:true,
			beforeSend:function loading(){
			},
			success:function(v){
				var data = window.JSON.parse(v);
				var myInterval = window.setInterval(function(){
					var q = data[question].question;
					var a = data[question].answer;
					$("#quizAsk").append("Question" +": "+q+"\n");
					while(q.indexOf("?") >= 0 || q.indexOf("#") >= 0 || q.indexOf("%") >= 0){
						q = q.replace("?","");
						q = q.replace("#","");
						q = q.replace("%","");
					}	
					$.ajax({
						type:"GET",
						url:"index/quiztest/question/"+q,
						async:true,
						beforeSend:function loading(){
						},
						success:function(b){
							$("#quizAnswer").append("Answer" +": "+b+"\n");
							if(b == a){
								$("#quizAnswer").append("Correct!!!\n");
								$("#quizStar"+correct).attr("src","images/star.png");
								correct ++;
							}else{
								$("#quizAnswer").append("Wrong!!!\n");
							}
						},
						error:function(){
						}
					});	
					question++;
					if(question == 5){
						window.clearInterval(myInterval);
						if(correct==5){
							alert("You have passed the exam");
							$("#map_school").hide(2000);
							$("#map-mainAlanStreet").show(2000);
						}else{
							alert("You failed the exam");
							$("#map_school").hide(2000);
							$("#map-mainAlanStreet").show(2000);
						}
					}
				},5000);
			},
			error:function(){
			}
		});		
	});
});